package com.zh.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

/**
 * 使用Druid加载数据源
 * <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
 *<property name="driverClassName" value="${driver}"></property>
 *<property name="url" value="${url}"></property>
 *<property name="username" value="${username}"></property>
 *<property name="password" value="${password}"></property>
 *</bean>
 */
public class JdbcConfig {

    @Value("${driver}")
    private String driverClassName;
    @Value("${url}")
    private String url;
    @Value("${username}")
    private String username;
    @Value("${password}")
    private String password;

    @Bean("dataSource")
    public DruidDataSource druidDataSource(){
        DruidDataSource dds = new DruidDataSource();
        dds.setDriverClassName(driverClassName);
        dds.setUrl(url);
        dds.setUsername(username);
        dds.setPassword(password);
        return dds;
    }

}
